package educationaladministrationsystem.CSM.Mapper.Service.Root;

import educationaladministrationsystem.CSM.Mapper.Service.ServiceInterface.RootInterface.RootFaculties;
import educationaladministrationsystem.Class.Faculties;
import educationaladministrationsystem.CSM.Mapper.Root.RootFacultiesMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
@Slf4j
public class RootFacultiesFacultiesService implements RootFaculties {
    @Autowired
    private RootFacultiesMapper rootFacultiesMapper;

    @Override
    public boolean addNewFaculties(Faculties faculties) {
        return rootFacultiesMapper.addNewFaculties(faculties, LocalDate.now().toString()) != 0;
    }

    @Override
    public List<Faculties> getFacultiesInformation(int page, int pageSum) {
        return rootFacultiesMapper.getFacultiesInformation((page - 1) * pageSum, pageSum);
    }

    @Override
    public boolean updateFacultiesInformation(Faculties faculties, String oldFacultiesId) {
        log.info(oldFacultiesId);
        return rootFacultiesMapper.updateFacultiesInformation(faculties, oldFacultiesId) != 0;
    }

    @Override
    public boolean deleteInformation(int deleteId) {
        return rootFacultiesMapper.deleteInformation(deleteId) != 0;
    }

    @Override
    public Integer getAllPage(int pageNumber) {
        double all = rootFacultiesMapper.getAllPage();
        return (int) Math.ceil(all / pageNumber);
    }
}
